<template>
  <div class="nav-list">
    <mu-grid-list ref="gridlistInline" class="gridlist-inline" :class="{'timeLine': type === 'timeLine'}" :padding="0" :cols="cols" :cell-height="cellHeight">
      <mu-grid-tile :cols="index == 0 ? 1 : 1" v-for="(item, index) in rowData" :key="index" @click="selectNav(item)">
        <div slot="title"  class="title-text" :style="{height: cellHeight + 'px'}" :class="{ 'selected' : item.checked }">
          <span class="title">{{item.name}}</span>
          <span class="sub" v-if="item.subTitle">{{item.subTitle}}</span>
          <div class="line" v-if="!type" v-show="item.checked"></div>
        </div>

      </mu-grid-tile>
    </mu-grid-list>
  </div>
</template>

<script>
export default {
  name: 'row-scroll',
  props: {
    rowData: {
      type: Array,
      default() {
        return []
      }
    },
    cols: {
      type: Number,
      default() {
        return 4
      }
    },
    type: {
      type: String,
      default() {
        return ''
      }
    },
    cellHeight: {
      type: Number,
      default() {
        return 50
      }
    }
  },
  created() {

  },
  mounted() {
    let vindex = 0
    console.log('this.rowData', this.rowData)
    this.rowData.forEach((element, index) => {
      if (element.checked) {
        vindex = index
      }
    })
    const leftMight = Math.max((window.innerWidth / this.cols) * (vindex + 0.5) - window.innerWidth / 2, 0)
    this.$refs.gridlistInline.$el.scrollLeft = leftMight
  },
  data() {
    return {
    }
  },
  methods: {
    selectNav(item) {
      this.rowData.forEach((element, index) => {
        if (item.id === element.id) {
          this.$set(this.rowData[index], 'checked', true)
        } else {
          this.$set(this.rowData[index], 'checked', false)
        }
      })
      this.$emit('select', item)
    }
  },
  computed: {
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" >
@import "src/assets/css/mixin.scss";
@import 'src/assets/css/variables.scss';
.nav-list{
  margin: 0px;
}
.gridlist-inline {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  .mu-grid-tile-wrapper{
    .mu-grid-tile{
      .mu-grid-tile-titlebar{
        height: auto;
        background-color: rgba(0, 0, 0, 0);
      }
      .mu-grid-tile-title-container{
        color: $color-text;
        text-align: center;
        margin-left: 0;
      }
    }
  }
  .title-text{
    height: 40px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: $font-size-medium-x;
    box-sizing: border-box;
    border-bottom: 2px solid rgba(0, 0, 0, 0);
    .title{
      font-size: 15px;
      color: #1a1a1a;
      padding: 0px 8px;
    }
    .sub{
      font-size: $font-size-small;
    }
    .line{
      background-color: $color-theme;
      height: 3px;
      position: absolute;
      bottom: 0;
      width: 12px;
      border-radius: 2px;
    }

  }
  .selected{
    .title{
      color: $color-theme;
    }
    color: $color-theme;
    // border-bottom: 2px solid $color-theme;
  }
}
.timeLine{
  .title-text{
    .title{
      font-size: 13px;
      line-height: 17px;
      margin-bottom: 5px;
      color: $color-text;
    }
  }
  .sub{
    line-height: 12px;
    font-size: 12px;
    transform: scale(0.8);
    color: #ACB1BF;
  }
  .selected{
    .title{
      background-color: $color-theme;
      color: white;
      padding: 0px 10px;
      border-radius: 8px;

    }
    .sub{
      color: $color-theme;

    }

    // border-bottom: 2px solid $color-theme;
  }
}
</style>
